package com.ywjg.serviceimp;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.ywjg.dao.AppShopDao;
import com.ywjg.dao.AppUserDao;
import com.ywjg.model.AppShop;
import com.ywjg.model.AppUser;
import com.ywjg.service.IAppShopService;
import com.ywjg.utils.Utils;

@Service
public class AppShopService implements IAppShopService {
	@Resource
	AppShopDao appShopDao;
	
	@Resource
	AppUserDao appUserDao;

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IAppShopService#findShopByUserId(int)
	 */
	public AppShop findShopByUserId(int id) {
		AppShop appshop = appShopDao.findByAppUserId(id);
		return appshop;
	}
	
	
	public AppShop findShopById(int id) {
		AppShop appshop = appShopDao.findOne(id);
		return appshop;
	}

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IAppShopService#createShop(com.ywjg.model.AppShop)
	 */
	public AppShop createShop(AppShop appShop) {
		AppShop appshop = appShopDao.save(appShop);
		return appshop;
	}
	
	
	
	@Transactional
	@Async
	public void setShopPoint(AppShop appShop) {
		
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String shopAddress = appShop.getShopAddress();
		String userPoint = Utils.getPoInteger(shopAddress);
		appShop.setShopPoint(userPoint);
		AppShop findOne = appShopDao.findOne(appShop.getId());
		Utils.copyPropertiesIgnoreNull(appShop, findOne);
		appShopDao.save(findOne);
	}
	
	
	
	
	public List<AppShop> findAllShop() {
		List<AppShop> allShop = appShopDao.findAll();
		return allShop;
	}
	
	
	
	
	
	
	

}
